#include <stdio.h>


int sort(int* arr, int l, int h)
{
	int i;
	int j;
	int k;
	int tmp;

	i = l;
	j = h;
	k = i;

	while (i < j)
	{
		while (j > k)
		{
			if (arr[j] < arr[k])
			{
				tmp = arr[j];
				arr[j] = arr[k];
				arr[k] = tmp;
				k = j;
				break;
			}
			else
			{
				j --;
			}
		}

		while (i < k)
		{
			if (arr[i] > arr[k])
			{
				tmp = arr[i];
				arr[i] = arr[k];
				arr[k] = tmp;
				k = i;
				break;
			}
			else
			{
				i ++;
			}
		}
	}

	return (k);
}

void quicksort(int* arr, int l, int h)
{
	int k;

	if (l < h)
	{
		k = sort(arr, l, h);
		quicksort(arr, l, k-1);
		quicksort(arr, k+1, h);
	}
}

void main()
{
	int i;
	int arr[9] = {4,7,9,2,6,1,5,8,3}; 
	int length;

	length = sizeof(arr)/sizeof(arr[0]);
	quicksort(arr, 0, length);

	for (i=0;i<length;i++)
	{
		printf("%d\r\n",arr[i]);
	}

	getchar();
}